package com.sy.controller.allocate;

import com.sy.bean.allocate.HomeInventory;
import com.sy.bean.allocate.Inventory;
import com.sy.bean.allocate.InventorySave;
import com.sy.bean.allocate.Stock;
import com.sy.common.bean.PageBean;
import com.sy.common.bean.ResultBean;
import com.sy.common.controller.BaseController;
import com.sy.service.allocate.InventoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(tags = "盘点列表")
@RestController
@RequestMapping("/api/inventory")
public class InventoryController extends BaseController {
    @Autowired
    InventoryService inventoryService;
    @PostMapping("/list")
    @ApiOperation("盘点列表")
    public ResultBean<PageBean<Inventory>> query(@RequestBody Map map){
        PageBean<Inventory> list = inventoryService.query(map);
        return success("盘点列表",list);
    }
    @PostMapping("/save")
    @ApiOperation("新增盘点记录")
    public ResultBean save(@RequestBody List<InventorySave> inventorySaveList) {
        int rs = inventoryService.batchSave(inventorySaveList);
        return rs>0?success("保存成功"):fail("保存失败");
    }
    @PostMapping("/export")
    @ApiOperation("导出盘点记录")
    public ResultBean export(@RequestBody Map map) {
        String url = inventoryService.exportInv(map);
        return success("导出盘点记录",url);
    }
    @PostMapping("/stock/list")
    @ApiOperation("库存列表")
    public ResultBean<PageBean<Stock>> queryStock(@RequestBody Map map){
        PageBean<Stock> list = inventoryService.queryStock(map);
        return success("盘点列表",list);
    }
    @GetMapping("/home/num")
    @ApiOperation("库存总量")
    public ResultBean<Inventory> queryHomeHouse(int eid){
        HomeInventory inventory = inventoryService.queryHomeInventory(eid);
        return success("库存总量",inventory);
    }
}
